<!--# layout("/common/layout.html",{"jsBase":"/js/content/ebookMain/"}){ -->

<form class="layui-form layui-form-pane" id="addForm" enctype="multipart/form-data"  lay-filter="editform">
    <input type="hidden" name="bookId" id="bookId">
    <input type="hidden" name="bookDesc" id="bookDesc">



        <div class="layui-form-item">
            <div class="layui-inline">
            <label class="layui-form-label">名称</label>
				<div class="layui-input-inline">
                                <input type="text" name="bookName" id="bookName" autocomplete="off" maxlength="50" class="layui-input" lay-verify="required">
				</div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">类型</label>
                <div class="layui-input-inline">
                    <select style="width:40%" class="select" name="bookType" id="bookType"  promtion="请选择类型" lay-verify="required">
                        <option value="">请选择类型</option>
                        <option value="11">作文大猜想</option>
                        <option value="12">提分少不了</option>
                        <option value="13">热点精读</option>
                    </select>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">作者</label>
                <div class="layui-input-inline">
                    <input type="text" name="author" id="author" autocomplete="off" maxlength="50" class="layui-input" lay-verify="required">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">章节数</label>
                <div class="layui-input-inline">
                    <input type="text" name="chapterNum" id="chapterNum" autocomplete="off" maxlength="50" class="layui-input" lay-verify="required|number">
                </div>
            </div>
        </div>


    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">简介</label>
<!--            <div class="layui-input-block" style="width:512px">-->
<!--                <textarea name="bookDesc"  id="bookDesc" placeholder="请输入" class="layui-textarea" ></textarea>-->
<!--            </div>-->

            <div class="layui-input-block" style="width:712px">

                <script id="chapterContentUE" type="text/plain" placeholder="请输入" >
                        ${ebookMain.bookDesc}
                </script>

            </div>

        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
        <label class="layui-form-label">电子书价格 </label>
            <div class="layui-input-inline">
                            <input type="text" name="ebookPrice" id="ebookPrice" autocomplete="off" maxlength="50" class="layui-input" lay-verify="required|number">
            </div>
        </div>
        <div class="layui-inline">
        <label class="layui-form-label" style="width:130px;">电子书已售基数</label>
            <div class="layui-input-inline">
                            <input type="text" name="ebookSales" id="ebookSales" autocomplete="off" maxlength="50" class="layui-input" >
            </div>
        </div>

    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <layui:image id="cover" tagName="书籍封面" tips=""/>
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-inline">
            <layui:singleFile id="url" tagName="下载地址" tips=""/>
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">完结类型</label>
            <layui:simpleDictSelect style='layui-input-inline' type="EBOOK_FINISH_TYPE" layVerify="required"
                                    id="finish" name="finish" value="" />

        </div>
        <div class="layui-inline">
            <label class="layui-form-label">可用标记</label>
            <div class="layui-input-inline">
                <input type="radio" name="bookStatus" value="1" checked title="是">
                <input type="radio" name="bookStatus" value="0" title="否">
            </div>
        </div>
    </div>

    <layui:submitButtons id="addButton" />
</form>
<!--#} -->
<script type="text/javascript"  src="${ctxPath}/plugins/ueditor/ueditor.config.js"></script>
<script type="text/javascript"  src="${ctxPath}/plugins/ueditor/ueditor.all.js"></script>
<script>

    let ueditor_config = {
        toolbars: [["undo", "redo", "|", "fontsize", "forecolor", "bold", "italic", "underline", "|", "justifyleft", "justifycenter", "justifyright", "justifyjustify", "lineheight", "|", "directionalityltr", "directionalityrtl", "indent", "|", "simpleupload", "|",  "spechars", "source", "|", "searchreplace", "|", "fullscreen","mobile"]],
        serverUrl: "${ctxPath}/content/ebookChapter/config",
        autoHeightEnabled: false,
        elementPathEnabled : false,　　//是否启用元素路径，默认是true显示
        wordCount:false,          //是否开启字数统计
        initialFrameHeight:500
    };
    var ue = UE.getEditor('chapterContentUE',ueditor_config);

    ue.ready(function() {

    });

    UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
    UE.Editor.prototype.getActionUrl = function(action) {
        if (action == 'uploadimage' || action == 'uploadscrawl' || action == 'uploadvideo') {
            return '${ctxPath}/content/ebookChapter/upload.json';
        } else {
            return this._bkGetActionUrl.call(this, action);
        }
    }


    Common.initImage();
layui.extend({
    loading: '../../../plugins/layui_extends/loading/loading',
}).define([ 'form', 'laydate', 'table','loading','ebookMainApi'], function(exports) {
    var form = layui.form;
    var ebookMainApi = layui.ebookMainApi;
    var index = layui.index;
    var isNew = true;
    <!--# if(!(isEmpty(ebookMainJson))){  -->
    isNew = false;
    <!--# } -->
    var view = {
        init:function(){
            Lib.initGenrealForm($("#addForm"),form);
            this.initSubmit();
        },
        initSubmit:function(){
            $("#addButton").click(function(){
                // $("#addButton").hide();
                // $("#addButton-loading").show();
                // $("#addButton-loading").loading();
                $("#bookDesc").val(ue.getContent());
                form.on('submit(form)', function(){
                    ebookMainApi.saveForm(isNew,$('#addForm'),function(){
                        parent.window.dataReload();
                        Common.info("保存成功");
                        Lib.closeFrame();
                    });
                });
            });

            $("#addButton-cancel").click(function(){
                Lib.closeFrame();
            });
        }

    }
    view.init();
    <!--# if(!(isEmpty(ebookMainJson))){  -->
    var formJson = ${ebookMainJson};
    form.val("editform",formJson);
    $(".image-preview").each(function() {
        $(this).attr("src",formJson[$(this).attr("id")]);
    });
    $(".file_link").each(function() {
        var a=document.createElement('a');
        var aJq = $(a);
        aJq.html("下载文件");
        aJq.attr("href",formJson[$(this).attr("id")]);
        aJq.attr("target","_blank");
        $(this).append(aJq);
    });
    <!--# } -->
});
</script>
